home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue31 / clinic / RoundU.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1997-12-14  |  1.3 KB  |  61 lines

  1. unit RoundU;
  2.  
  3. interface
  4.  
  5. uses
  6.   WinProcs, WinTypes, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  7.   Dialogs, StdCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Button1: TButton;
  12.     Label1: TLabel;
  13.     Button2: TButton;
  14.     procedure Button1Click(Sender: TObject);
  15.     procedure Button2Click(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.   public
  19.     { Public declarations }
  20.   end;
  21.  
  22. var
  23.   Form1: TForm1;
  24.  
  25. implementation
  26.  
  27. {$R *.DFM}
  28.  
  29. procedure TForm1.Button1Click(Sender: TObject);
  30. var
  31.   AFloat: Extended;
  32.   AnInt: Longint;
  33. begin
  34.   AFloat := StrToFloat(
  35.     InputBox('Rounding Test', 'Enter a floating point number', '2.5'));
  36.   AnInt := Round(AFloat);
  37.   Label1.Caption := Format('Round(%f) = %d', [AFloat, AnInt])
  38. end;
  39.  
  40. procedure TForm1.Button2Click(Sender: TObject);
  41. var
  42.   AFloat: Extended;
  43.   AnInt: Longint;
  44. begin
  45.   AFloat := StrToFloat(
  46.     InputBox('Rounding Test', 'Enter a floating point number', '2.5'));
  47.   asm
  48.     { Push AFloat onto co-processor stack }
  49.     FLD     AFloat
  50.     { Round float to an integer }
  51.     FRNDINT
  52.     { Pop integer into AnInt }
  53.     FISTP   AnInt
  54.     { Ensure co-pro ops are complete before proceeding }
  55.     FWAIT
  56.   end;
  57.   Label1.Caption := Format('Round(%f) = %d', [AFloat, AnInt])
  58. end;
  59.  
  60. end.
  61.